﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ro.fortech.training.mvc.control;
using Model;




namespace View
{
    public partial class frmStartStopWork : Form
    {
        LoginScreen loginScreen=new LoginScreen();
        AccountController logged=new AccountController();
        Controller control = new Controller();       
        
        public frmStartStopWork()
        {
            InitializeComponent();
           
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            NavigateController screen = new NavigateController();
           
            if (screen.ShowLoginScreen())
            {
                loginScreen.Show();
                this.Hide();
            }
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
                logged.UserWorking(AccountController.userLogged);
                TimeSpan minlate = control.GetMinutesLate(DateTime.Now);
                txtMinutesLate.Text = minlate.Hours.ToString() + "h " + minlate.Minutes.ToString() + "min";
                txtWorkDuration.Text = "";
                StartEnable(AccountController.userLogged);
                StopEnable(AccountController.userLogged);
              
        }

        private void frmStartStopWork_Load(object sender, EventArgs e)
        {
            StartEnable(AccountController.userLogged);
            StopEnable(AccountController.userLogged);
            TimeSpan minlate = TimeSpan.Parse(AccountController.userLogged.MinLate);
            txtMinutesLate.Text = minlate.Hours.ToString()+"h "+minlate.Minutes.ToString()+"min";                             
        }


        private void StartEnable(User user)
        {
            if (user.IsWorking)
                btnStart.Enabled = false;
            else btnStart.Enabled = true;
           
        }

        private void StopEnable(User user)
        {
            if (!user.IsWorking)
                btnStop.Enabled = false;
            else btnStop.Enabled = true;
           
                
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            //logged.UserNotWorking(AccountController.userLogged,DateTime.Now.TimeOfDay);
            StartEnable(AccountController.userLogged);
            StopEnable(AccountController.userLogged);
            TimeSpan workduration = control.GetWorkDuration(DateTime.Now.TimeOfDay);
            txtWorkDuration.Text = workduration.Hours.ToString() + "h " + workduration.Minutes.ToString() + "min";         
        }

       
      

       

       
    }
}
